<%--
  Created by IntelliJ IDEA.
  User: Lily
  Date: 2017/9/12
  Time: 14:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.web.my12306.util.*" %>
<%
    String loginname = "";
//    String autoLogin = "";
    Cookie[] cookies = request.getCookies();//取所有的cookie
    if (cookies != null) {
        for (Cookie c : cookies) {//循环遍历
            if ("loginname".equals(c.getName())) {
                loginname = c.getValue();//从cookie取值保存
            }
//            if ("autoLogin".equals(c.getName())) {
//                autoLogin = c.getValue();
//            }
        }
    }

    //自动登录---未完成（失败）
//    if (!TextUtils.isEmpty(autoLogin)) {
//        response.sendRedirect(request.getContextPath() + "/Admin/autoLogin");
//    }
%>
<html>
<head>
    <meta charset="UTF-8">
    <title>admin_login</title>
    <link rel="stylesheet" type="text/css" href="../js/util/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../js/util/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../js/util/easyui/demo/demo.css">
    <script type="text/javascript" src="../js/util/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="../js/util/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<form action="../Admin/doLogin" method="post" name="adminLogin" id="adminLogin">
    <div style="margin:20px 0;"></div>
    <div class="easyui-panel" title="管理员登录" style="width:600px">
        <div style="padding:10px 60px 20px 60px">
            <table cellpadding="5">
                <tr>
                    <td></td>
                    <td colspan="3">
                        <% String msg = (String) request.getAttribute("msg");
                            if (msg != null) {
                        %>
                        <%= msg %>
                        <%
                            }
                        %>
                    </td>
                </tr>
                <tr>
                    <td>管理员工号:</td>
                    <td><input class="easyui-textbox" data-options="required:true"
                               validType="loginname"
                               id="loginname" name="loginname"
                               value="<%= loginname %>"></input></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>密码:</td>
                    <td><input class="easyui-passwordbox" data-options="required:true"
                               validType="password"
                               id="password" name="password"></input></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td>验证码:</td>
                    <td><input type="text" name="codein"></td>
                    <td><img src="../Admin/ValidateCode" id="codeimage"></td>
                    <td><input type="button" onclick="javascript:reloadcode()" value="刷新"></td>
                </tr>
                <tr>
                    <td colspan="3"><input name="autoLogin" type="checkbox" value="1" style=" margin:0 auto;"/>自动登录</td>
                </tr>
            </table>
            <div style="text-align:center;padding:5px">
                <input type="submit" value="提交">
                <input type="reset" value="重置">
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
    $.extend($.fn.validatebox.defaults.rules, {
        loginname: {
            validator: function (value, param) {
//                    return /^[a-z]+[0-9]+$/gi.test(value);
                var loginname = value;
                var name_check_1 = /[a-zA-Z]+/;//必须有字母
                var name_check_2 = /[0-9]+/;//必须有数字
                var name_check_3 = /^[a-zA-Z]{1}[a-zA-Z0-9_.]{5,19}$/;
                var name_check = true;
                var name_c = "用户名必须要有";

                if (!name_check_1.test(loginname)) {
                    name_check = false;
                    name_c = name_c + "字母（不论大小写）";
                }
                if (!name_check_2.test(loginname)) {
                    name_check = false;
                    name_c = name_c + "数字";
                }
                if (!name_check_3.test(loginname)) {
                    name_check = false;
                    name_c = "字母开头，不能出现除“_”“.”以外的特殊字符"
                }
                return name_check;
            },
            message: '管理员工号是6-20位字母和数字的组合（字母开头，不包含除“_”“.”以外的特殊字符）'
            //'管理员工号由大（小）字母和数字组成'
        },
        password: {
            validator: function (value, param) {
                return /^[a-z0-9_.]{6,20}$/gi.test(value);
            },
            message: '密码是6-20的字符组合（不包含除“_”“.”以外的特殊字符）'
        }
    });
    //        function login() {
    //            $('#adminLogin').form('submit', {
    //                onSubmit: function () {
    //                    return $(this).form('enableValidation').form('validate');
    //                }
    //            });
    //        }

    //        验证码刷新
    function reloadcode() {
        document.getElementById("codeimage").src = "../Admin/ValidateCode?t=" + new Date();
    }
</script>
</body>
</html>
